package cn.wolfcode.trip.admin.controller;

import cn.wolfcode.trip.base.domain.Product;
import cn.wolfcode.trip.base.query.ProductQueryObject;
import cn.wolfcode.trip.base.service.IProductService;
import cn.wolfcode.trip.base.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("product")
public class ProductController {

    @Autowired
    private IProductService productService;

    @RequestMapping("list")
    public String user(@ModelAttribute("qo") ProductQueryObject qo, Model model){
        model.addAttribute("pageInfo",productService.listAll(qo));
        return "product/list";
    }

    @RequestMapping("getContent")
    @ResponseBody
    public Object getContent(Long id){
        return productService.getProductContentById(id);
    }


    /*@RequestMapping("saveOrUpdate")
    @ResponseBody
    public JsonResult saveOrUpdate(MultipartFile file, Product entity) {
        //有文件就上传
        if (file!=null&&file.getSize()>0){
            String url = UploadUtil.upload(file, UploadUtil.PATH + "/upload");
            entity.setPics(url);
        }
        productService.saveOrUpdate(entity);
        return new JsonResult();
    }*/

    @RequestMapping("saveOrUpdate")
    @ResponseBody
    public JsonResult saveOrUpdate(Product product,String content) {
        productService.saveOrUpdate(product);
        return new JsonResult();
    }
}
